package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.SyncLoanDiffLogDao;
import com.fdb.efp.nls.service.domain.SyncLoanDiffLog;
import com.fdb.efp.nls.service.facade.SyncLoanDiffLogService;
import com.fdb.efp.nls.service.vo.SyncLoanDiffLogVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * Service Impl: 借据信息差异表服务实现
 *
 * @author gcb
 * @date 2020-04-24
 */
@Service("syncLoanDiffLogService")
public class SyncLoanDiffLogServiceImpl implements SyncLoanDiffLogService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(SyncLoanDiffLogServiceImpl.class);

    @Autowired
    private SyncLoanDiffLogDao syncLoanDiffLogDao;

    /**
     * 新增数据
     *
     * @param syncLoanDiffLogVo
     * @return
     */
    @Override
    public int insert(SyncLoanDiffLogVO syncLoanDiffLogVo) {
        logger.debug("当前新增数据为:" + syncLoanDiffLogVo.toString());
        int num = 0;
        try {
            SyncLoanDiffLog syncLoanDiffLog = new SyncLoanDiffLog();
            beanCopy(syncLoanDiffLogVo, syncLoanDiffLog);
            num = syncLoanDiffLogDao.insert(syncLoanDiffLog);
        } catch (Exception e) {
            logger.error("新增数据发生异常!", e);
            num = -1;
        }
        logger.debug("当前新增数据条数为:" + num);
        return num;
    }

    /**
     * 根据主键删除信息
     *
     * @param syncLoanDiffLogVo
     * @return
     */
    @Override
    public int deleteByPk(SyncLoanDiffLogVO syncLoanDiffLogVo) {
        logger.debug("当前删除数据条件为:" + syncLoanDiffLogVo);
        int num = 0;
        try {
            SyncLoanDiffLog syncLoanDiffLog = new SyncLoanDiffLog();
            beanCopy(syncLoanDiffLogVo, syncLoanDiffLog);
            num = syncLoanDiffLogDao.deleteByPk(syncLoanDiffLog);
        } catch (Exception e) {
            logger.error("删除数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + syncLoanDiffLogVo + "删除的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键更新信息
     *
     * @param syncLoanDiffLogVo
     * @return
     */
    @Override
    public int updateByPk(SyncLoanDiffLogVO syncLoanDiffLogVo) {
        logger.debug("当前修改数据为:" + syncLoanDiffLogVo.toString());
        int num = 0;
        try {
            SyncLoanDiffLog syncLoanDiffLog = new SyncLoanDiffLog();
            beanCopy(syncLoanDiffLogVo, syncLoanDiffLog);
            num = syncLoanDiffLogDao.updateByPk(syncLoanDiffLog);
        } catch (Exception e) {
            logger.error("修改数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + syncLoanDiffLogVo + "修改的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键查询详情
     *
     * @param inSyncLoanDiffLogVo
     * @return
     */
    @Override
    public SyncLoanDiffLogVO queryByPk(SyncLoanDiffLogVO inSyncLoanDiffLogVo) {
        logger.debug("当前查询参数信息为:" + inSyncLoanDiffLogVo);
        try {
            SyncLoanDiffLog querySyncLoanDiffLog = new SyncLoanDiffLog();
            beanCopy(inSyncLoanDiffLogVo, querySyncLoanDiffLog);
            SyncLoanDiffLog queryRslSyncLoanDiffLog = syncLoanDiffLogDao.queryByPk(querySyncLoanDiffLog);
            if (Objects.nonNull(queryRslSyncLoanDiffLog)) {
                return beanCopy(queryRslSyncLoanDiffLog, new SyncLoanDiffLogVO());
            } else {
                logger.debug("当前查询结果为空!");
            }
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return null;
    }

    @Override
    public int batchInsert(List<SyncLoanDiffLogVO> list) throws Exception {
        return this.syncLoanDiffLogDao.batchInsert((List<SyncLoanDiffLog>) beansCopy(list, SyncLoanDiffLog.class));
    }
}
